﻿using Halcon二次开发.Model;
using Halcon二次开发.Model.用户属性;
using Halcon二次开发.Tools;
using Halcon二次开发.View.登录界面;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.账号信息界面
{
    public partial class UrseIDForm : Form
    {
        public static UrseIDForm urseIDForm;
        public static UrseIDForm GetSingle()
        {
            if (urseIDForm == null)
            {
                urseIDForm = new UrseIDForm();
            }
            return urseIDForm;
        }
        public UrseIDForm()
        {
            InitializeComponent();
        }

        string ID = "";

        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UrseIDForm_Load(object sender, EventArgs e)
        {
            foreach (UrseInformation item in StaicResouce.UrseInforMationDb) {
                dataGridView1.Rows.Add(item.ID,item.PassWord, item.Post);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UrseIDForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        /// <summary>
        /// 单元格值被修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            int paper = -1;
            foreach (UrseInformation item in StaicResouce.UrseInforMationDb) {
                if (item.ID == ID)
                {
                    StaicResouce.UrseInforMationDb[e.RowIndex].ID = dataGridView1.Rows[e.RowIndex].Cells[0].Value+"";
                    StaicResouce.UrseInforMationDb[e.RowIndex].PassWord = dataGridView1.Rows[e.RowIndex].Cells[1].Value+"";
                    StaicResouce.UrseInforMationDb[e.RowIndex].Post = dataGridView1.Rows[e.RowIndex].Cells[2].Value+"";
                    paper = 1; break;
                }
            }
            HelpJsons.Write(StaicResouce.UrseInforMationDb, $@"Data\账户信息\信息.json");
        }

        /// <summary>
        /// 单机单元格事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            ID = dataGridView1.Rows[e.RowIndex].Cells[0].Value+"";


        }
    }
}
